<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript">


function saveFile(){
	var form  = $("#form1");
	var valid = form.form("validate");
	if(valid){
		sortInputField();
		goAjax({
			url:"${admin_base}/model/saveSubItem.at",
			data:form.serialize(),
			callback:function(json){
				$.messager.alert('提示','保存成功','info',function(){
					
				});
			}
		});
	}
}

function sortInputField(){
	$("#table tbody tr").each(function(i){
		$(this).find("input").each(function(i2){
			var name = $(this).attr("name");
			$(this).attr("name",$.formatString(name,i));
		});
		$(this).find("select").each(function(i2){
			var name = $(this).attr("name");
			$(this).attr("name",$.formatString(name,i));
		});
	});
}


var i=0;
function addItem(){
	var itemModel = $("#table_input tbody tr").first().clone();
	itemModel.find("td:last").html('<a href="#" class="easyui-linkbutton" style="width:50px" onclick="removeItem(this)">删除</a>');
	$("#table tbody").append(itemModel);
	//$("#table_input tbody tr").find("input").val("");
	$.parser.parse("#form1");
}

function removeItem(elm){
	$(elm).parent().parent().remove();
}

</script>

<div id="p" class="easyui-panel" title="文件编辑-${file.name }" style="height: 800px;padding: 5px">
<form action="${admin_base}/model/saveSubItem.at" id="form1">
<input type="hidden" name="modelPath" value="${param.id }"/>
<textarea id="tplTxt" name="tplTxt" rows="10" cols="30" style="width: 98%;height: 400px">${content }</textarea>
<br/><br/>

<div class="easyui-panel" title="子栏目" style="text-align: center;"
			data-options="iconCls:'icon-save',collapsible:true">
	<table id="table">
		<tbody>
			<c:forEach items="${list}" var="item" varStatus="sts">
				<tr>
				<th>说明：</th>
				<td><input type="text" name="modelItems[{0}].itemLabel" style="width:120px" value="${item.itemLabel }" class="easyui-validatebox textbox"  required="true"/></td>
				<th>字段名：</th>
				<td><input type="text" readonly="readonly" name="modelItems[{0}].field" style="width:120px" value="${item.field }" class="easyui-validatebox textbox"  required="true"/></td>
				<th>类型：</th>
				<td>
					<select name="modelItems[{0}].dataType">
						<option value="1"${item.dataType==1?' selected="selected"':'' }>文本</option>
						<option value="2"${item.dataType==2?' selected="selected"':'' }>图片</option>
						<option value="3"${item.dataType==3?' selected="selected"':'' }>数字</option>
					</select>
				</td>
				<th>唯一性：</th>
				<td>
					<select name="modelItems[{0}].isSingle">
						<option value="true"${item.isSingle?' selected="selected"':'' }>唯一</option>
						<option value="false"${item.isSingle?'':' selected="selected"' }>不唯一</option>
					</select>
				</td>
				<th>空：</th>
				<td>
					<select name="modelItems[{0}].isRequired">
						<option value="true"${item.isRequired?' selected="selected"':'' }>不可以</option>
						<option value="false"${item.isRequired?'':' selected="selected"' }>可以</option>
					</select>
				</td>
				<th>顺序：</th>
				<td><input type="number" name="modelItems[{0}].priority" style="width:50px" value="${item.priority }" class="easyui-validatebox textbox"  required="true"/></td>
				<td>
					<a href="#" class="easyui-linkbutton" style="width:50px" onclick="removeItem(this)">删除</a>
				</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
</div>
</form><br/>
<div class="easyui-panel" title="新增" style="text-align: center;"
			data-options="iconCls:'icon-save',collapsible:true">
	<table id="table_input">
		<tbody>
			<tr>
				<th>说明：</th>
				<td><input type="text" name="modelItems[{0}].itemLabel" value="" class="easyui-validatebox textbox" style="width:120px"  required="true"/></td>
				<th>字段名：</th>
				<td><input type="text" name="modelItems[{0}].field" value="" class="easyui-validatebox textbox"  style="width:120px" required="true"/></td>
				<th>类型：</th>
				<td>
					<select name="modelItems[{0}].dataType">
						<option value="1">文本</option>
						<option value="2">图片</option>
						<option value="3">数字</option>
					</select>
				</td>
				<th>唯一性：</th>
				<td>
					<select name="modelItems[{0}].isSingle">
						<option value="true">唯一</option>
						<option value="false">不唯一</option>
					</select>
				</td>
				<th>空：</th>
				<td>
					<select name="modelItems[{0}].isRequired">
						<option value="true">不可以</option>
						<option value="false">可以</option>
					</select>
				</td>
				<th>顺序：</th>
				<td><input type="number" name="modelItems[{0}].priority" value="0" style="width:50px" class="easyui-validatebox textbox"  required="true"/></td>
				<td>
					<a href="#" class="easyui-linkbutton" style="width:50px" onclick="addItem()">新增</a>
				</td>
		</tbody>
	</table>
</div>
	
<br/><br/>
<center>
<a href="#" class="easyui-linkbutton" id="backBtn" data-options="iconCls:'icon-back'"  style="width:80px">返  回</a>
<a href="#" class="easyui-linkbutton" id="saveFileBtn" data-options="iconCls:'icon-save'"  style="width:80px" onclick="saveFile()">保  存</a>
</center>
</div>
